﻿var list = {
    productionOrdersId:'',
    productionNumber: '',
    client: '',
    orderNumber: '',
    priority: '',
    remark: '',
    addTime: ''
}
var plist = [];
layui.use('layer', function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;
    $(function () {
        UpdateShow();
    })
    function UpdateShow() {
        $.ajax({
            url: '/ProductionOrders/ProductionOrdersModel',
            type: 'get',
            data: { ProductionOrdersId: localStorage.getItem("productionOrdersId"), token: localStorage.getItem("token") },
            success: function (res) {
                var s = JSON.parse(res)
                plist = s.data.list
                $(s.data).each(function () {
                    $('#ProductionNumber').val(this.productionNumber)   
                    $('#Client').val(this.client)
                    $('#OrderNumber').val(this.orderNumber)
                    $('#AddTime').val(this.addTime.substring(0,10))
                    $('#Priority').val(this.priority)
                    $('#remark').val(this.remark)
                    list.productionOrdersId = this.productionOrdersId
                    list.client = this.client
                    list.orderNumber = this.orderNumber
                    list.addTime = this.addTime
                    list.priority = this.priority
                    list.remark = this.remark
                    form.render('select');
                })
                table.render({
                    elem: '#ProductionOrdersTable',  // 表格元素的选择器
                    page: {
                        limit: 5,
                        limits: [5, 8, 10]
                    },
                    toolbar: '#toolbarDemo',
                    defaultToolbar: ['exports'],
                    cols: [[
                        { type: 'checkbox', fixed: 'left', title: '复选框' },
                        { field: 'finishedProductNumbering', title: '成品编号' },
                        { field: 'finishedProductModel', title: '规格型号' },
                        { field: 'finishedProductUnit', title: '单位' },
                    ]],
                    // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
                    data: plist
                });
            }
        })
    }

    ///添加
    form.on('submit(demo-ddd)', function (data) {
        list.productionNumber = $("#ProductionNumber").val();
        list.client = $("#Client").val();
        list.orderNumber = $("#OrderNumber").val();
        list.priority = $("#Priority").val();
        list.remark = $("#remark").val();
        list.addTime = $("#AddTime").val();
        console.log(list)
        $.ajax({
            url: '/ProductionOrders/ProductionOrdersUpdate',
            type: 'post',
            data: { data: JSON.stringify(list), token: localStorage.getItem("token") },
            success: function (res) {
                var s = JSON.parse(res)
                console.log(res)
                if (s.data >= 1) {
                    layer.alert("修改成功");
                    setTimeout(function () {
                        window.location.href = "/ProductionOrders/ProductionOrdersShowView";
                    }, 2000);
                    
                }
                else {
                    layer.alert("修改失败");
                }
            }
        })
        return false; // 阻止默认 form 跳转

    })
});
